/**
 * File DialogFrame.java 
 */
package cs.gui;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import cs.entity.UserTextMessage;

/**
 * Passive class for constructing the dialog frame.<p>
 * Package  cs.gui
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 */
@SuppressWarnings("serial")
public class DialogFrame extends JFrame  {

	private JPanel contentPane;
	private JTextField inputArea;
	private JTextArea textArea;
	private JButton btnSendText ; 
	private JButton btnSendFile ; 
	private FileTransfert transfert;

	
	/**
	 * Create the frame.
	 */
	public DialogFrame(String name) {
		setTitle("Conversation avec "+name);
		initGUI();
		setVisible(true);
	}
	
	
	public FileTransfert getTransfert() {
		return transfert;
	}

	public void setTransfert(FileTransfert transfert) {
		this.transfert = transfert;
	}

	
	
	private void initGUI() {
	//	setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 576, 361);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		textArea = new JTextArea();
		textArea.setBackground(UIManager.getColor("EditorPane.background"));
		textArea.setEditable(false);
		
		inputArea = new JTextField();
		inputArea.setColumns(10);
		
		btnSendText = new JButton("Envoyer");
		btnSendText.setToolTipText("Envoyer");
		btnSendText.setIcon(new ImageIcon("src/cs/gui/images/arrow_right_16.png"));
		
		
		
		btnSendFile = new JButton("Fichier...");
	
		btnSendFile.setIcon(new ImageIcon("src/cs/gui/images/folder_search_16.png"));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(20)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(textArea, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(inputArea, GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
							.addGap(18)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(btnSendFile, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
								.addComponent(btnSendText, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
					.addGap(20))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(20)
					.addComponent(textArea, GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(14)
							.addComponent(btnSendText)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnSendFile))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addGap(14)
							.addComponent(inputArea, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)))
					.addGap(24))
		);
		contentPane.setLayout(gl_contentPane);
		this.getRootPane().setDefaultButton(btnSendText);

	}
	
	
	
	/**
	 * Display the message in the historic of conversation Area
	 * @param u UserTextMessage to display
	 */
	public void newMsg(UserTextMessage u) {
		textArea.append(u.getRemoteUser().getUsername()+" : "+u.getMessage()+"\n"); 
	}
	
	public JTextField getInputArea() {
		return inputArea;
	}
	
	
	
	public void emptyInputArea() {
		inputArea.setText(""); 
	}
	public JButton getSendText() {
		return btnSendText;
	}
	public void setSendText(JButton sendText) {
		this.btnSendText = sendText;
	}
	public void setTextArea(JTextArea textArea) {
		this.textArea = textArea;
	}	
	
	/**
	 * @return the btnSendFile
	 */
	public JButton getBtnSendFile() {
		return btnSendFile;
	}
	
}
